const { list, save, setLatest, remove } = require('./data/app-packages')
const { add, packageItems } = require('./data/app-package-items')
const base = '/movieserver'

module.exports = [{
  url: `${base}/appPackages/[1-9][0-9]*/files`,
  type: 'get',
  response: config => {
    const id = config.url.match(/[1-9][0-9]*/)
    return { success: true, data: packageItems(id) }
  }
}, {
  url: `${base}/appPackages/[1-9][0-9]*/zip`,
  type: `get`,
  response: config => {
    const id = config.url.match(/[1-9][0-9]*/)
    return { success: false, message: '收到请求,id=' + id + ',请部署服务测试' }
  }
}, {
  url: `${base}/appPackages`,
  type: 'get',
  response: config => {
    const { page, limit } = config.query
    return list(page, limit)
  }
}, {
  url: `${base}/appPackages`,
  type: 'post',
  response: config => {
    const id = save(config.body)
    return { success: true, data: id }
  }
}, {
  url: `${base}/appPackages/[1-9][0-9]*`,
  type: 'put',
  response: config => {
    const id = config.url.match(/[1-9][0-9]*/)
    setLatest(id)
    return { success: true }
  }
}, {
  url: `${base}/appPackages/[1-9][0-9]*`,
  type: 'delete',
  response: config => {
    const id = config.url.match(/[1-9][0-9]*/)
    remove(id)
    return { success: true }
  }
}, {
  url: `${base}/appPackageItems/[1-9][0-9]*/file`,
  type: 'post',
  response: config => {
    const id = config.url.match(/[1-9][0-9]*/)
    return { success: true, message: '好了,收到了[' + id + ']' }
  }
}, {
  url: `${base}/appPackageItems`,
  type: 'post',
  response: config => {
    const id = add(config.body)
    return { success: true, data: id }
  }
}]
